Skip to main content

BitStream

A Bitstream that is a stream of bits! (What did you expect!)


Functions

writeBits

BitStream:writeBits( value, numBits )

Writes a sequence of bits to the stream.

Arguments:

  • value [ integer ] The value to write.
  • numBits [ integer ] The number of bits to write from the value.

readBits

BitStream:readBits( numBits )

Reads a sequence of bits from the stream.

Arguments:

  • numBits [ integer ] The number of bits to read.

Returns: -[ integer ] The extracted value.


writeUInt

BitStream:writeUInt( value, numBits )

Writes an unsigned integer in Bigian format.

Arguments:

  • value [ integer ] The unsigned integer value to write.
  • numBits [ integer ] The number of bits to use for the value.

readUInt

BitStream:readUInt( numBits )

Reads an unsigned integer in Bigian format.

Arguments:

  • numBits [ integer ] The number of bits to read.

Returns:

  • [ integer ] The extracted unsigned integer.

writeInt

BitStream:writeInt( value, numBits )

Writes a signed integer in Bigian format.

Arguments:

  • value [ integer ] The signed integer value to write.
  • numBits [ integer ] The number of bits to use for the value.

readInt

BitStream:readInt( numBits )

Reads a signed integer in Bigian format.

Arguments:

  • numBits [ integer ] The number of bits to read.

Returns:

  • [ integer ] The extracted signed integer.

writeByte

BitStream:writeByte( value )

Writes a single byte (8 bits) to the stream.

Arguments:

  • value [ integer ] The byte value to write (0-255).

readByte

BitStream:readByte()

Reads a single byte (8 bits) from the stream.

Returns:

  • [ integer ] The extracted byte value.

writeBytes

BitStream:writeBytes( bytes )

Writes a sequence of bytes to the stream.

Arguments:

  • bytes [ string ] The byte sequence to write.

readBytes

BitStream:readBytes( numBytes )

Reads a sequence of bytes from the stream.

Arguments:

  • numBytes integer The number of bytes to read.

Returns:

  • [ string ] The extracted byte sequence.

writeFloat

BitStream:writeFloat( value )

Writes a floating-point number in Bigian format (32-bit IEEE 754).

Arguments:

  • value [ number ] The float value to write.

readFloat

BitStream:readFloat()

Reads a floating-point number in Bigian format (32-bit IEEE 754).

Returns:

  • [ number ] The extracted float value.

reset

BitStream:reset()

Resets the bit stream, clearing all data.


align

BitStream:align()

Aligns the bit stream to the next byte boundary.


tostring

BitStream:tostring()

Converts the bit stream to a string representation.

Returns:

  • [ string ] The string representation of the bit stream.